
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head  th:replace="admin/index::head">
    <meta charset="utf-8">
    <title>
        权限规则
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/css/main.css}" media="all">
</head>
<body>
<div  class="layui-layout layui-layout-admin" >
    <div class="layui-header header header-demo" th:replace="admin/index :: menu"></div>
    <div class="layui-side layui-bg-black x-side show_list" style="left:0px;" id="" th:replace="admin/index::menu1"></div>

    <div class="layui-tab layui-tab-card site-demo-title x-main" lay-filter="x-tab" lay-allowclose="true" style="left: 220px;border-left: solid 2px #2299ee;">
        <ul class="layui-tab-title">
            <li class="layui-this"> 权限列表 <i class="layui-icon layui-unselect layui-tab-close">ဆ</i> </li>
        </ul>
        <div class="x-nav">
                    <span class="layui-breadcrumb">
                      <a><cite>首页</cite></a>
                      <a><cite>会员管理</cite></a>
                      <a><cite>权限规则</cite></a>
                    </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
        </div>
        <div class="x-body">

            <xblock>
                <button class="layui-btn layui-btn-danger" onclick="delAll()">
                    <i class="layui-icon">&#xe640;</i>批量删除</button>
                <button class="layui-btn" onclick="rule_add('添加权限','/administrator/auth_ruleadd.html','600','500')"><i class="layui-icon">&#xe608;</i>添加</button>
                <span class="x-right" style="line-height:40px">共有数据：<span class="layui-badge" th:text="${authority.total}"></span> 条</span>
            </xblock>

            <table class="layui-table">
                <thead>
                <tr>
                    <th>
                        <input id="all" type="checkbox"  name="" value="">
                    </th>
                    <th>
                        序号
                    </th>
                    <th>
                        权限编码
                    </th>
                    <th>
                        权限名称
                    </th>
                    <th>
                        权限规则
                    </th>
                    <th>
                        等级
                    </th>
                    <th>
                        时间
                    </th>
                    <th>
                        状态
                    </th>
                    <th>
                        操作
                    </th>
                </tr>
                </thead>
                <tbody id="ulContainer">

                </tbody>
            </table>

            <div id="page"
                 style="float: right; margin-right: 145px; position: relative; top: -15px;">
                <span id="totalPage"  style='display: none' th:text="${authority.pages}"></span>
                <ul class="pagination" id="pagination-demo"></ul>
            </div>
        </div>
    </div>
</div>
<th:block th:include="admin/index::script"></th:block>
<script th:src="@{/myjs/authrule.js}"></script>
<script>
    layui.use(['element','laypage','layer','form'], function(){
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
        form = layui.form();//弹出层

        //监听提交
        form.on('submit(*)', function(data){
            console.log(data);
            //发异步，把数据提交给php
            layer.alert("增加成功", {icon: 6});
            $('#x-link').prepend('<tr><td><input type="checkbox"value="1"name=""></td><td>1</td><td>'+data.field.rules+'</td><td>'+data.field.name+'</td><td>'+data.field.cname+'</td><td class="td-manage"><a title="编辑"href="javascript:;"onclick="rule_edit(\'编辑\',\'link-edit.html\',\'4\',\'\',\'510\')"class="ml-5"style="text-decoration:none"><i class="layui-icon">&#xe642;</i></a> <a title="删除"href="javascript:;"onclick="rule_del(this,\'1\')"style="text-decoration:none"><i class="layui-icon">&#xe640;</i></a></td></tr>');
            return false;
        });
    })

    //以上模块根据需要引入

    //批量删除提交
    function delAll () {
        layer.confirm('确认要删除吗？',function(index){
            //捉到所有被选中的，发异步进行删除
            var ch=$("[name=ids]:checked"); //所有被选中状态的元素
            if(ch.length==0){
                //没有被选中的元素-提示并且代码不往下执行
                // alert("请至少选择要删去的一本书");
                layer.msg("至少需要选中一行数据！", {icon: 1});
                return; //代码不往下执行
            }
            //有选中状态的元素-提交请求（url）并且需要携带要被删去元素的id
            // var url="delMany.do?ids=";
            //遍历被选中的元素，并且拿到相应的值
            for(var i=0;i<ch.length;i++){
                url+=$(ch[i]).val()+",";
            }
            var url="/administrator/deleteByIds?ids=";
            //遍历被选中的元素，并且拿到相应的值
            for(var i=0;i<ch.length;i++){
                url+=$(ch[i]).val()+",";
            }
            $.ajax({
                type:"post",
                url :url,
                success:function (result) {
                    if (result.status==1){
                        layer.msg('删除成功', {icon: 1});
                        window.location.reload();
                    }else {
                        layer.msg('删除失败', {icon: 1});
                    }
                }
            });
        });
    }

    /*添加*/
    function rule_add(title,url,w,h){
        x_admin_show(title,url,w,h);
    }
    /**
     * 权限状态
     **/
    function rule_status(obj,id,e) {
        layer.confirm(e==1?'你确定要启用吗？':'你确定要禁用吗？',{icon: 3, title:'提示'},function(index){
            $.ajax({
                type:"post",
                url:"/administrator/editAuth",
                data:{id:id,status:e},
                dataType:"json",
                success:function(data)
                {
                    if(data.status==1){
                        //发异步把用户状态进行更改
                        $(obj).attr("class","layui-btn layui-btn-danger ");
                        $(obj).text("隐藏");
                        $(obj).remove();
                        layer.msg(data.info,{icon: 6,time:1000});
                        setTimeout(function(){
                            window.location.reload();
                        },1000);return false;
                    }else{
                        //发异步把用户状态进行更改
                        $(obj).attr("class","layui-btn layui-btn-normal ");
                        $(obj).text("显示");
                        $(obj).remove();
                        layer.msg(data.info,{icon: 5,time:1000});return false;
                    }
                }
            });

        });
    }

    //-编辑
    function rule_edit (title,url,id,w,h) {
        url = url+id;
        x_admin_show(title,url,w,h);
    }

    /*删除*/
    function rule_del(obj,id){
        layer.confirm('确认要删除吗？',{icon: 3, title:'提示'},function(index){
            $.ajax({
                type:"delete",
                url:"/administrator/deleteAuthById"+id,
                dataType:"json",
                async:true,
                success:function(data){
                    if(data.status==1){
                        layer.msg(data.msg,{icon:6,time:1000});
                        setTimeout(function(){
                            window.location.reload();
                        },1000);return false;
                    }else{
                        layer.msg(data.msg,{icon:5,time:1000});return false;
                    }
                }
            });
        });
    }
</script>

</body>
</html>